home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Trading on the Edge
/
Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin
/
mac
/
Shared
/
MovingAverage
/
MovingAverage.m
< prev
next >
Wrap
Text File
|
1993-07-18
|
785b
|
43 lines
(* Copyright 1988,1990 Wolfram Research, Inc. *)
(*:Version: Mathematica 2.0 *)
(*:Name: Statistics`MovingAverage` *)
(*:Author:
Wolfram Research, Inc.
*)
(*:Keywords: moving average *)
(*:Requirements: none. *)
(*:Warnings: none. *)
BeginPackage["Statistics`MovingAverage`"]
MovingAverage::usage=
"MovingAverage[list,n] returns a list of the n-th moving averages of list."
Begin["`Private`"]
Mean[list_List] := (Plus @@ list)/Length[list]
MovingAverage[list:{{_,_}..}, n_Integer] :=
Block[{list1, list2},
{list1, list2} = Transpose[list];
Table[
{list1[[i+Floor[n/2]]],
Mean[Take[list2,{i, i+n}]]},
{i,1, Length[list]-n}]
]
MovingAverage[list_List, n_Integer] :=
Table[Mean[Take[list, {i, i+n}]],
{i,1, Length[list]-n}]
End[ ]
EndPackage[ ]